local pojue = fk.CreateSkill{
  name = "hanqing__pojue",
}

Fk:loadTranslationTable{
  ["hanqing__pojue"] = "迫决",
  [":hanqing__pojue"] = "回合开始时，你可以依次令体力值为一、二、三的角色各选择一项：1.摸一张牌；2.将一张牌当本回合未被使用过的基本牌使用。"..
  "缺少对应体力值的角色时，改为由你执行。",

  ["#hanqing__pojue-use"] = "迫决：将一张牌当基本牌使用，或点“取消”摸一张牌",
}

pojue:addEffect(fk.TurnStart, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return target == player and (player:hasSkill(pojue.name) or player:getMark("hanqing__pojue_invoke") > 0)
  end,
  on_cost = function(self, event, target, player, data)
    return player:getMark("hanqing__pojue_invoke") > 0 or
      player.room:askToSkillInvoke(player, {
        skill_name = pojue.name,
      })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for i = 1, 3, 1 do
      local targets = table.filter(room:getAlivePlayers(), function (p)
        return p.hp == i
      end)
      if #targets > 0 then
      elseif not player.dead then
        targets = {player}
      end
      for _, p in ipairs(targets) do
        if not p.dead then
          if p:isNude() and #p:getHandlyIds() == 0 then
            p:drawCards(1, pojue.name)
          else
            local disabled = {}
            room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
              local card = e.data.card
              if card.type == Card.TypeBasic then
                table.insertIfNeed(disabled, card.trueName)
              end
            end, Player.HistoryTurn)
            local all_names = player:getViewAsCardNames(pojue.name, Fk:getAllCardNames("b"), nil, disabled)
              if #all_names == 0 or
              not room:askToUseVirtualCard(p, {
                name = all_names,
                skill_name = pojue.name,
                prompt = "#hanqing__pojue-use",
                cancelable = true,
                extra_data = {
                  bypass_times = true,
                  extraUse = true,
                },
                card_filter = {
                  n = 1,
                }
              }) then
              p:drawCards(1, pojue.name)
            end
          end
        end
      end
    end
  end,
})

return pojue
